using System;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace SS
{
	public class frmChangePass : Form
	{
		public string StrUsername = "";
		private Func objFun = new Func();
		private IContainer components = null;
		private Button cmdSave;
		private Button cmdClose;
		private TextBox txtPWRepeat;
		private Label label3;
		private TextBox txtPWNew;
		private Label label2;
		private TextBox txtPWOld;
		private Label label1;
		private Label label4;
		public frmChangePass()
		{
			this.InitializeComponent();
		}
		private void cmdClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void cmdSave_Click(object sender, EventArgs e)
		{
			if (this.txtPWOld.Text.Trim() == string.Empty)
			{
				MessageBox.Show("Hãy nhập mật khẩu cũ!            ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.txtPWOld.Focus();
			}
			else
			{
				if (this.txtPWNew.Text == string.Empty)
				{
					MessageBox.Show("Hãy nhập mật khẩu mới!           ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
					this.txtPWNew.Focus();
				}
				else
				{
					if (this.txtPWRepeat.Text == string.Empty)
					{
						MessageBox.Show("Hãy nhắc lại mật khẩu!          ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
						this.txtPWRepeat.Focus();
					}
					else
					{
						if (this.txtPWRepeat.Text != this.txtPWNew.Text)
						{
							MessageBox.Show("Xác nhận mật khẩu không đúng!   ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
							this.txtPWRepeat.Text = "";
							this.txtPWRepeat.Focus();
						}
						else
						{
							SqlConnection sqlConnection = new SqlConnection(this.objFun.strConnectionString);
							SqlCommand sqlCommand = new SqlCommand("SELECT * FROM TabUser WHERE [userName] = @Username AND [Pass] = @Pass", sqlConnection);
							sqlCommand.Parameters.AddWithValue("@Username", this.StrUsername);
							sqlCommand.Parameters.AddWithValue("@Pass", this.objFun.CryptographyMD5(this.txtPWOld.Text));
							sqlConnection.Open();
							SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
							if (sqlDataReader.HasRows)
							{
								SqlConnection sqlConnection2 = new SqlConnection(this.objFun.strConnectionString);
								SqlCommand sqlCommand2 = new SqlCommand("UPDATE TabUser SET [Pass] = @PassWord WHERE ([userName] = @UserName)", sqlConnection2);
								sqlCommand2.Parameters.AddWithValue("@UserName", this.StrUsername);
								sqlCommand2.Parameters.AddWithValue("@PassWord", this.objFun.CryptographyMD5(this.txtPWNew.Text));
								sqlConnection2.Open();
								sqlCommand2.ExecuteNonQuery();
								sqlConnection2.Close();
								sqlConnection2.Dispose();
								MessageBox.Show("Mật khẩu đã được thay đổi                    ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
								base.Close();
							}
							else
							{
								MessageBox.Show("Mật khẩu cũ không đúng!                       ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
								this.txtPWOld.Text = string.Empty;
								this.txtPWOld.Focus();
							}
							sqlConnection.Close();
							sqlConnection.Dispose();
						}
					}
				}
			}
		}
		private void frmChangePass_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmChangePass));
			this.cmdSave = new Button();
			this.cmdClose = new Button();
			this.txtPWRepeat = new TextBox();
			this.label3 = new Label();
			this.txtPWNew = new TextBox();
			this.label2 = new Label();
			this.txtPWOld = new TextBox();
			this.label1 = new Label();
			this.label4 = new Label();
			base.SuspendLayout();
			this.cmdSave.BackColor = SystemColors.Control;
			this.cmdSave.Cursor = Cursors.Hand;
			this.cmdSave.FlatStyle = FlatStyle.System;
			this.cmdSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.cmdSave.ForeColor = Color.Black;
			this.cmdSave.ImageAlign = ContentAlignment.MiddleLeft;
			this.cmdSave.Location = new Point(181, 131);
			this.cmdSave.Name = "cmdSave";
			this.cmdSave.Size = new Size(90, 28);
			this.cmdSave.TabIndex = 8;
			this.cmdSave.Text = "Ghi nhận";
			this.cmdSave.UseVisualStyleBackColor = false;
			this.cmdSave.Click += new EventHandler(this.cmdSave_Click);
			this.cmdClose.BackColor = SystemColors.Control;
			this.cmdClose.Cursor = Cursors.Hand;
			this.cmdClose.FlatStyle = FlatStyle.System;
			this.cmdClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.cmdClose.ForeColor = Color.Black;
			this.cmdClose.ImageAlign = ContentAlignment.MiddleLeft;
			this.cmdClose.Location = new Point(272, 131);
			this.cmdClose.Name = "cmdClose";
			this.cmdClose.Size = new Size(90, 28);
			this.cmdClose.TabIndex = 1;
			this.cmdClose.Text = "Thoát  [ ESC ]";
			this.cmdClose.UseVisualStyleBackColor = false;
			this.cmdClose.Click += new EventHandler(this.cmdClose_Click);
			this.txtPWRepeat.Location = new Point(131, 96);
			this.txtPWRepeat.Name = "txtPWRepeat";
			this.txtPWRepeat.PasswordChar = '*';
			this.txtPWRepeat.Size = new Size(231, 21);
			this.txtPWRepeat.TabIndex = 3;
			this.label3.AutoSize = true;
			this.label3.BackColor = Color.Transparent;
			this.label3.Location = new Point(61, 99);
			this.label3.Name = "label3";
			this.label3.Size = new Size(67, 15);
			this.label3.TabIndex = 5;
			this.label3.Text = "Xác nhận : ";
			this.txtPWNew.Location = new Point(131, 69);
			this.txtPWNew.Name = "txtPWNew";
			this.txtPWNew.PasswordChar = '*';
			this.txtPWNew.Size = new Size(231, 21);
			this.txtPWNew.TabIndex = 2;
			this.label2.AutoSize = true;
			this.label2.BackColor = Color.Transparent;
			this.label2.Location = new Point(38, 72);
			this.label2.Name = "label2";
			this.label2.Size = new Size(90, 15);
			this.label2.TabIndex = 3;
			this.label2.Text = "Mật khẩu mới : ";
			this.txtPWOld.Location = new Point(131, 42);
			this.txtPWOld.Name = "txtPWOld";
			this.txtPWOld.PasswordChar = '*';
			this.txtPWOld.Size = new Size(231, 21);
			this.txtPWOld.TabIndex = 1;
			this.label1.AutoSize = true;
			this.label1.BackColor = Color.Transparent;
			this.label1.Location = new Point(20, 45);
			this.label1.Name = "label1";
			this.label1.Size = new Size(108, 15);
			this.label1.TabIndex = 1;
			this.label1.Text = "Mật khẩu hiện tại : ";
			this.label4.BackColor = Color.Transparent;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 0);
			this.label4.Location = new Point(12, 9);
			this.label4.Name = "label4";
			this.label4.Size = new Size(350, 21);
			this.label4.TabIndex = 9;
			this.label4.Text = "THAY ĐỔI MẬT KHẨU CỦA TÀI KHOẢN";
			this.label4.TextAlign = ContentAlignment.MiddleCenter;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(374, 169);
			base.Controls.Add(this.label4);
			base.Controls.Add(this.txtPWRepeat);
			base.Controls.Add(this.label3);
			base.Controls.Add(this.cmdSave);
			base.Controls.Add(this.txtPWNew);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.cmdClose);
			base.Controls.Add(this.txtPWOld);
			base.Controls.Add(this.label1);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.MaximizeBox = false;
			this.MaximumSize = new Size(390, 203);
			base.MinimizeBox = false;
			this.MinimumSize = new Size(390, 203);
			base.Name = "frmChangePass";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " .: Thay đổi mật khẩu";
			base.KeyDown += new KeyEventHandler(this.frmChangePass_KeyDown);
			base.ResumeLayout(false);
			base.PerformLayout();
		}
	}
}
